package com.derbysoft.lowcostadapter.web.action.admin.hotel;

import com.derbysoft.common.web.struts2.support.PaginateActionSupport;
import com.derbysoft.lowcostadapter.commons.model.Hotel;
import com.derbysoft.lowcostadapter.commons.repository.HotelRepository;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.springframework.beans.factory.annotation.Autowired;

public class ListAction extends PaginateActionSupport {
    @Autowired
    private HotelRepository hotelRepository;

    private Hotel hotelCondition;

    private Hotel newHotel;

    @Action("list")
    public String list() {
        ActionContext.getContext().setLocale(ServletActionContext.getRequest().getLocale());
        setPaginater(hotelRepository.findByCondition(hotelCondition, getPaginater()));
        return SUCCESS;
    }

    public String view() {
        newHotel = hotelRepository.load(hotelCondition.getPropertyID());
        return SUCCESS;
    }

    public Hotel getHotelCondition() {
        return hotelCondition;
    }

    public void setHotelCondition(Hotel hotelCondition) {
        this.hotelCondition = hotelCondition;
    }

    public Hotel getNewHotel() {
        return newHotel;
    }

    public void setNewHotel(Hotel newHotel) {
        this.newHotel = newHotel;
    }
}
